package com.example.tasks

import okio.buffer
import okio.sink
import okio.source
import java.io.File
import java.io.FilenameFilter

const val dirPath = "/Users/zhengjianxin/Documents/ux设计稿/资源/首页+视频/"
const val prefix = "home_main_"
fun main() {
    val filter = FilenameFilter { p0, p1 ->
        return@FilenameFilter p1.contains("@2x.")
    }
    val fileArray = File(dirPath).listFiles(filter)

    val newFolder = File("$dirPath/android")
    newFolder.mkdirs()
    fileArray.forEach { file ->
        val fileName = file.name.replace("@2x", "")
        println(fileName)
        val rename =
            "$prefix${fileName.substring(0, fileName.lastIndexOf("."))}${fileName.substring(fileName.lastIndexOf("."))}"
        file.source().buffer().use { source ->
            File(newFolder, rename).sink().buffer().use {
                it.writeAll(source)
            }
        }
        file.delete()
        println(rename)
    }
}